
#include "World.h"

World::World(){

	cameraX = cameraY = 0;
	cameraArea = NULL;
}

bool World::init(char* mapFile){

	if(!Mapa::init(mapFile))
		return false;

	//Default initial camera position
	cameraArea = &Mapa::areas[0][0];

	return true;
}

void World::loop(){
	Mapa::loop();
}

void World::render(SDL_Surface* destSurface){
	
	cameraArea->render(destSurface, cameraX, cameraY);
}

void World::cleanup(){
	
	Mapa::cleanup();
}

void World::keyPressed(SDLKey sym){
	
	switch(sym)
	{
		case SDLK_RIGHT:
			
			if(cameraX < cameraArea->getWidth() - 32)
				cameraX++;

			break;

		case SDLK_LEFT:

			if(cameraX > 0)
				cameraX--;
			
			break;

		case SDLK_UP:

			if(cameraY > 0)
				cameraY--;
			
			break;

		case SDLK_DOWN:

			if(cameraY < cameraArea->getHeight() - 24)
				cameraY++;
			
			break;

		case SDLK_SPACE:
			if(cameraArea == &Mapa::areas[0][0])
				cameraArea = &Mapa::areas[1][1];
			else
				cameraArea = &Mapa::areas[0][0];
		break;
	}
}
